﻿using ChurchDiary.Common;
using ChurchDiary.DAL.Contract;
using ChurchDiary.DAL.DAL;
using ChurchDiary.TableEntity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChurchDiary.DAL.Methods
{
    public class DAL_EmailTemplate : DataAccess, IEmailTemplate
    {
        #region EmailTemplate
        public EntityEmailTemplate GetEmailTemplate(string TemplateType)
        {
            EntityEmailTemplate EmailTemplate = new EntityEmailTemplate();
            try
            {
                using (DbCommand dbCommand = SQLServer.GetStoredProcCommand("[dbo].[GET_EmailTemplate]"))
                {
                    using (DbConnection con = SQLServer.CreateConnection())
                    {
                        SQLServer.AddInParameter(dbCommand, "@TemplateType", DbType.String, eTemplate.LOGIN);
                        using (IDataReader OReader = SQLServer.ExecuteReader(dbCommand))
                        {
                            if (OReader == null)
                            {
                                return EmailTemplate;
                            }
                            while (OReader.Read())
                            {
                                EmailTemplate.EmailTemplateId = (Guid)OReader["EmailTemplateId"];
                                EmailTemplate.TemplateContent = OReader["TemplateContent"].ToString();
                                EmailTemplate.TemplateSubject = OReader["TemplateSubject"].ToString();
                                EmailTemplate.TemplateType = OReader["TemplateType"].ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
            }
            return EmailTemplate;
        }
        #endregion
    }
}
